﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Objects;
using System.Data.Entity;

namespace Web.Infrastructure.Storage {
    public class EFCodeFirstReadOnlySession:IReadOnlySession {
        DbContext _context;
        public EFCodeFirstReadOnlySession(DbContext context)
        {
            _context = context;
        }
        public T Single<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) where T : class, new() {
            return All<T>().FirstOrDefault(expression);
        }

        public IQueryable<T> All<T>() where T : class, new() {
            return _context.Set<T>().AsQueryable().AsNoTracking();
        }
    }
}